package com.iotp.service.userUserRef;

import com.iotp.dao.userUserRef.UserUserRefDAO;
import com.iotp.entity.userUserRef.TempUser;
import com.iotp.entity.userUserRef.UserUserRef;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service("userUserRefService")
public class UserUserRefServiceImpl implements UserUserRefService {
    @Autowired
    private UserUserRefDAO userUserRefDAO;
    @Override
    public Long add(UserUserRef userUserRef) {
        this.userUserRefDAO.insert(userUserRef);
        return userUserRef.getId();
    }

    @Override
    public List<UserUserRef> queryByCondition(UserUserRef userUserRef) {
        return this.userUserRefDAO.selectByCondition(userUserRef);
    }

    @Override
    public List<TempUser> queryUserName() {
        List<TempUser> list = new ArrayList<>();
        List<HashMap> res = this.userUserRefDAO.selectUserName();
        if(null != res && !res.isEmpty()){
            res.forEach(item ->{
                TempUser t = new TempUser();
                t.setUserId(Long.parseLong(item.get("id")+""));
                t.setUserName(item.get("USER_NAME_CN")+"");
                list.add(t);
            });
        }
        return list;
    }

    @Override
    public UserUserRef queryById(Long id) {
        return this.userUserRefDAO.selectById(id);
    }
}
